package de.bazinga.rotw.menu;

import java.util.Iterator;

import com.jme.image.Texture;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
import com.jmex.game.state.GameStateManager;

import de.bazinga.rotw.game.Game;
import de.bazinga.rotw.game.RotwGameState;
import de.bazinga.rotw.menu.item.MenuItem;

public class InfoMenu extends Menu {

	public InfoMenu() {
		super("infoMenu");
	}
	
	
	protected void init() {		
		// Background
		Quad bgQuad = new Quad("bg",
				Game.getGame().getDisplay().getWidth(), 
				Game.getGame().getDisplay().getHeight());
		
		bgQuad.setRenderQueueMode(Renderer.QUEUE_ORTHO);   
	 	
		bgQuad.setLocalTranslation(new Vector3f(
				Game.getGame().getDisplay().getWidth()/2,
				Game.getGame().getDisplay().getHeight()/2,
				0));
		
		TextureState bg = Game.getGame().getDisplay().getRenderer().createTextureState();
		bg.setEnabled(true);
		bg.setTexture(TextureManager.loadTexture(RotwGameState.class
				.getClassLoader().getResource("background/menuBg.png"),
				Texture.MinificationFilter.BilinearNearestMipMap,
				Texture.MagnificationFilter.Bilinear));
		
		bgQuad.setRenderState(bg);
		
		bgQuad.setLightCombineMode(Spatial.LightCombineMode.Off);
		bgQuad.updateRenderState();
		
		getRootNode().attachChild(bgQuad);
	}
	
	
	protected void initMenuItems() {
		otherItems.put("heading", 
				new MenuItem("Du bist gestorben!",
						"",
						ColorRGBA.red,
						2f,
						250,
						Game.getGame().getDisplay().getHeight() - 50));
		
		menuItems.put("mainMenu", 
				new MenuItem("Zum Hauptmenue",
						"mainMenu",
						ColorRGBA.red,
						2f,
						300,
						Game.getGame().getDisplay().getHeight()-500));
	}
	
	protected void handleClick(String item) {
		if(menuItems.containsKey(item)) {
			if(item.equals("mainMenu")) {
				GameStateManager.getInstance().getChild("mainMenu").setActive(true);
				this.setActive(false);
			}
		}
	}
	
	public void setInfoText(String text) {
		otherItems.get("heading").setText(
				text);
	}
	
	protected void handleHover(MenuItem hoverItem) {
		Iterator<MenuItem> it = menuItems.values().iterator();
		while(it.hasNext()) {
			MenuItem item = it.next();
			if(hoverItem == item) {
				item.setTextColor(ColorRGBA.yellow);
			}else{
				item.setTextColor(ColorRGBA.red);
			}
		}
	}
}